<html>
<head><meta charset="utf-8"><title>miri trying to reborrow for Unique · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html">miri trying to reborrow for Unique</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="181287159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287159">(Nov 21 2019 at 09:15)</a>:</h4>
<p>Hi, I'm testing this library: <a href="https://github.com/Michael-F-Bryan/const-arrayvec" target="_blank" title="https://github.com/Michael-F-Bryan/const-arrayvec">https://github.com/Michael-F-Bryan/const-arrayvec</a><br>
I'm getting a miri error but i'm not quite sure if it's a false positive or is the code unsound:<br>
<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=bb0b383aca6792aa7e1dc96a9979ffa3" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=bb0b383aca6792aa7e1dc96a9979ffa3">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=bb0b383aca6792aa7e1dc96a9979ffa3</a><br>
<span class="user-mention" data-user-id="120791">@RalfJ</span> <span class="user-mention" data-user-id="124288">@oli</span></p>



<a name="181287328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287328">(Nov 21 2019 at 09:18)</a>:</h4>
<p>I'm not sure, but <a href="https://github.com/Michael-F-Bryan/const-arrayvec/blob/147553ca706176fe5cf1d56b2334a198bfba197a/src/lib.rs#L188" target="_blank" title="https://github.com/Michael-F-Bryan/const-arrayvec/blob/147553ca706176fe5cf1d56b2334a198bfba197a/src/lib.rs#L188">https://github.com/Michael-F-Bryan/const-arrayvec/blob/147553ca706176fe5cf1d56b2334a198bfba197a/src/lib.rs#L188</a> may be nuking the borrow stack for <code>tail</code></p>



<a name="181287571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287571">(Nov 21 2019 at 09:22)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> I tried switching places between the <code>tail</code> and <code>set_len</code> and it didn't help.</p>



<a name="181287599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287599">(Nov 21 2019 at 09:23)</a>:</h4>
<p>hmm</p>



<a name="181287606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287606">(Nov 21 2019 at 09:23)</a>:</h4>
<p>Ha. moving <code>self.set_len(new_length);</code> to the end of the function resolves this error.<br>
Is this somehow unsoundness? (i.e. should be fixed) or is this miri not being able to determine that the borrow has ended?</p>



<a name="181287614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287614">(Nov 21 2019 at 09:23)</a>:</h4>
<p>yea</p>



<a name="181287615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287615">(Nov 21 2019 at 09:23)</a>:</h4>
<p>that is unsound</p>



<a name="181287620"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287620" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287620">(Nov 21 2019 at 09:23)</a>:</h4>
<p>^^</p>



<a name="181287623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287623">(Nov 21 2019 at 09:24)</a>:</h4>
<p>the placement is very much on purpose</p>



<a name="181287673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287673">(Nov 21 2019 at 09:24)</a>:</h4>
<p>you can inline the body of <code>set_len</code></p>



<a name="181287686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287686">(Nov 21 2019 at 09:24)</a>:</h4>
<p>if you set it at the end, if dropping elements panics, you still have access to the elements that were dropped but didn't panic</p>



<a name="181287690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287690">(Nov 21 2019 at 09:24)</a>:</h4>
<p>Meaning that the change to len <em>needs</em> to be only after dropping?</p>



<a name="181287709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287709">(Nov 21 2019 at 09:25)</a>:</h4>
<p>If you want to know more about this google "pre-pooping your pants rust drop"</p>



<a name="181287723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287723">(Nov 21 2019 at 09:25)</a>:</h4>
<p>very amusing blog post</p>



<a name="181287736"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287736" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287736">(Nov 21 2019 at 09:25)</a>:</h4>
<p>oh so you're saying the opposite? that if I resolve miri's error by setting the len only afterwards this <em>introduces</em> unsoundness? hmm</p>



<a name="181287743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287743">(Nov 21 2019 at 09:25)</a>:</h4>
<p>will do :)</p>



<a name="181287751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287751">(Nov 21 2019 at 09:25)</a>:</h4>
<p>oh that's related to <span class="user-mention" data-user-id="132920">@gnzlbg</span> PR to Vec</p>



<a name="181287831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287831">(Nov 21 2019 at 09:26)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/64432" target="_blank" title="https://github.com/rust-lang/rust/pull/64432">https://github.com/rust-lang/rust/pull/64432</a></p>



<a name="181287965"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181287965" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181287965">(Nov 21 2019 at 09:28)</a>:</h4>
<p>so inlining <code>set_len</code> works too. I don't understand</p>



<a name="181288892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181288892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181288892">(Nov 21 2019 at 09:44)</a>:</h4>
<p>Like Oli said, read “pre-pooping your pants”</p>



<a name="181288926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181288926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181288926">(Nov 21 2019 at 09:45)</a>:</h4>
<p>I wonder what people reading Rust threads about pooping pants think about us, but that has become the technical term <span aria-label="laughter tears" class="emoji emoji-1f602" role="img" title="laughter tears">:laughter_tears:</span></p>



<a name="181291959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181291959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181291959">(Nov 21 2019 at 10:29)</a>:</h4>
<p><span class="user-mention" data-user-id="249222">@Elichai Turkel</span> lol I think you replicated <a href="https://github.com/bluss/arrayvec/pull/144" target="_blank" title="https://github.com/bluss/arrayvec/pull/144">https://github.com/bluss/arrayvec/pull/144</a></p>



<a name="181292990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181292990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181292990">(Nov 21 2019 at 10:44)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> lol, i'll also PR the changes after I finish reading the blog post (and actually understand why calling a function with &amp;mut self is inherently different than inlining it :P )</p>



<a name="181639779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181639779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181639779">(Nov 22 2019 at 14:01)</a>:</h4>
<p>the problem with the <code>&amp;mut self</code> function is mutable reference</p>



<a name="181639811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181639811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181639811">(Nov 22 2019 at 14:01)</a>:</h4>
<p>a function <code>fn foo(x: &amp;mut T)</code> must be able to rely on <code>x</code> being the only pointer to this instance of <code>T</code></p>



<a name="181639870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181639870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181639870">(Nov 22 2019 at 14:02)</a>:</h4>
<p>so if there are aliases that were created before (such as raw ptrs) and used later, that's illegal -- it makes <code>x</code> not the only live pointer</p>



<a name="181728818"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181728818" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181728818">(Nov 23 2019 at 19:50)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I was about to write "isn't that an inefficiency of the borrow checker? " but then I realized this can definitely be unsound:</p>
<div class="codehilite"><pre><span></span>fn main() {
    let mut a = vec![20, 20, 20];
    dbg!(a.capacity());
    let a_slice = unsafe { std::slice::from_raw_parts(a.as_ptr(), a.len()) };
    a.extend_from_slice(&amp;[64u8; 64]);
    dbg!(a.capacity());
    dbg!(a_slice);
}
</pre></div>



<a name="181728831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181728831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181728831">(Nov 23 2019 at 19:51)</a>:</h4>
<p>and I finished pre pooping my pants :)</p>



<a name="181820274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/miri%20trying%20to%20reborrow%20for%20Unique/near/181820274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/miri.20trying.20to.20reborrow.20for.20Unique.html#181820274">(Nov 25 2019 at 13:07)</a>:</h4>
<p>that code actually <em>writes</em> to <code>a</code> though (inside <code>extend_from_slice</code>), it doesnt just create a mutable ref</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>